package com.heima.leetcode.practice;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: leetcode 80. 删除排序数组中的重复项 II
 * @date 2025/5/15 9:54
 */
public class E80 {
    public int removeDuplicates(int[] nums) {
        int index = 0, repeat = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[index]) {
                repeat++;
                if (repeat <= 2) {
                    nums[++index] = nums[i];
                }
            } else {
                nums[++index] = nums[i];
                repeat = 1;
            }
        }
        return index + 1;
    }
}
